package com.umeox.moto.watch.fitness.ui.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.*
import com.umeox.moto.watch.fitness.R
import com.umeox.moto.watch.fitness.db.model.TodayChallenge
import java.util.*

/**
 * Created by Rambo 2021/5/18
 * Describe:
 */
class ChallengeResultDialog(
    context: Context,
    private val currentChallenge: TodayChallenge,
    private val isSuccess: Boolean
) :
    Dialog(context) {

    private lateinit var mResultIv: ImageView
    private lateinit var mCurrentChallengeLevelDesc: TextView
    private lateinit var mResultTv: TextView

    private lateinit var mRewardsTv: TextView


    private var actionClickListener: ActionClickListener? = null

    interface ActionClickListener {
        fun onContinue()
        fun onEnd()
    }

    fun setActionClickListener(listener: ActionClickListener) {
        actionClickListener = listener
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        init()
    }


    private fun init() {
        setContentView(
            LayoutInflater.from(context).inflate(R.layout.dialog_challenge_result, null)
        )

        mResultIv = findViewById(R.id.iv_result)
        mCurrentChallengeLevelDesc = findViewById(R.id.tv_challenge_level_tip)
        mResultTv = findViewById(R.id.tv_challenge_result_desc)
        mRewardsTv = findViewById(R.id.tv_rewards)

        mCurrentChallengeLevelDesc.text = currentChallenge.challengeTimesLevel
        if (isSuccess) {
            mResultIv.setImageResource(R.drawable.ic_challenge_medal)
            mResultTv.text = context.resources.getString(R.string.congratulations_str)
            mRewardsTv.text =
                String.format(Locale.getDefault(), "+%d", currentChallenge.rewardValue)
        } else {
            mResultIv.setImageResource(R.drawable.ic_challenge_fail)
            mResultTv.text = context.resources.getString(R.string.challenge_failed_str)
            mRewardsTv.text = String.format(Locale.getDefault(), "+%d", 0)
        }


        val lp = window!!.attributes
        lp.width = 240
        lp.height = 240
        window!!.attributes = lp
    }

}